﻿/******************************************************************************
 *  作者：       Maxzhang1985
 *  创建时间：   2012/4/10 14:05:41
 *
 *
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExtendPropertyLib;
using System.Collections.ObjectModel;
using DatabaseSchemaReader.DataSchema;
using System.Xml.Serialization;
using ExORMDesginer.Plugin;
namespace ExORMDesginer.Models
{
    public class FolderInfo:BusinessInfoBase<FolderInfo>
    {
        public FolderInfo()
        {
            FolderCollection = new SerializableObservableCollection<FolderInfo>();
            TableCollection = new SerializableObservableCollection<DbEntity>();

           
        }


        /// <summary>
        /// 类型
        /// </summary>
        public string InfoType { set; get; }

        public bool IsRoot { set; get; }

        public static ExtendProperty NameProperty = RegisterProperty(v => v.Name);
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { set { SetValue(NameProperty, value); } get { return (string)GetValue(NameProperty); } }


        public static ExtendProperty FolderCollectionProperty = RegisterProperty(v => v.FolderCollection);
        /// <summary>
        /// 文件夹集合
        /// </summary>
        public SerializableObservableCollection<FolderInfo> FolderCollection { set { SetValue(FolderCollectionProperty, value); } get { return (SerializableObservableCollection<FolderInfo>)GetValue(FolderCollectionProperty); } }


        [field: NonSerialized]
        [XmlIgnore]
        public ObservableCollection<object> Items
        {
            get
            {
                ObservableCollection<object> childNodes = new ObservableCollection<object>();
                foreach (var folder in this.FolderCollection)
                    childNodes.Add(folder);
                foreach (var entry in this.TableCollection)
                    childNodes.Add(entry);
                 
                return childNodes;
            }
        }    
      
    
        public static ExtendProperty TableCollectionProperty = RegisterProperty(v => v.TableCollection);
        /// <summary>
        /// 实体集合
        /// </summary>
        [field: NonSerialized]
        [XmlIgnore]
        public SerializableObservableCollection<DbEntity> TableCollection { set { SetValue(TableCollectionProperty, value); } get { return (SerializableObservableCollection<DbEntity>)GetValue(TableCollectionProperty); } }


        SerializableObservableCollection<string> nameList = null;
        /// <summary>
        /// 存储实体的名称，用于再次载入实体集合是使用。
        /// </summary>
        public SerializableObservableCollection<string> TableNames
        {
            set
            {
                nameList = value;
            }
            get
            {
                SerializableObservableCollection<string> names = new SerializableObservableCollection<string>();
                foreach (var entry in this.TableCollection)
                    names.Add(entry.Name);
                if(names.Count> 0)
                    return names;
                return nameList;
            }
        }

    }
}
